<template>
  <div class="app-container">
    <div class="filter-container">
        <div style="margin:10px;">
          <label ><p>项目标题：{{temp.title}}</p></label>
         
          <label v-if="type == 'ziliao'"><p>项目介绍图文详情</p> </label>
          <label v-else-if="type == 'fangan'"><p>投资方案图文详情</p></label>
          <label v-else-if="type == 'quanyi'"><p>股东权益图文详情</p></label>
          <label v-else-if="type == 'youshi'"><p>项目优势图文详情</p></label>
        </div>
       
       <el-form ref="dataForm"  :model="temp" label-position="left" class="form-container" >
        <el-form-item  v-if="type == 'ziliao'">
           <tinymce v-model="temp.projectInfo"  :height="300" />
        </el-form-item>
        <el-form-item  v-else-if="type == 'fangan'" >
           <tinymce v-model="temp.investmentContent"  :height="300" />
        </el-form-item>
        <el-form-item v-else-if="type == 'quanyi'">
           <tinymce v-model="temp.power"  :height="300" />
        </el-form-item>
        <el-form-item v-else-if="type == 'youshi'">
           <tinymce v-model="temp.projectAdvantage"  :height="300" />
        </el-form-item>
      </el-form>
        <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateData()">
          提交
        </el-button>
      </div>
  </div>
  </div>
</template>

<script>
import Tinymce from '@/components/Tinymce'

import { GQL } from '@/api/article'

export default {
  components: { Tinymce },
  data() {
    return {
      type:'',
      pid:'',
      textMap: {
        ziliao: '项目资料',
        youshi: '项目优势',
        fangan: '投资方案',
        quanyi: '项目权益'
      },
      temp: {
        projectInfo:'',//项目介绍
        projectAdvantage:'',//项目优势
        investmentContent:'',//投资方案
        power:""//股东权益
      },
   
     
    }
  },
  created() {
    let id=this.$route.query.id;
    let type=this.$route.query.type;
    this.type = type
    console.log('a===============',this.type)
    this.pid = id
    this.projectInfo()
  },
  methods: {
    //获取项目信息
    projectInfo(){
         const query = {
               "operationName": "allSlProjects",
"query": "query allSlProjects($filter: SlProjectFilter) { allSlProjects( filter: $filter) { totalCount nodes {title pid investmentContent power projectAdvantage projectInfo} } }",
"variables":{"filter": {"pid": {"equalTo": this.pid}}}
        }
       GQL(query).then(response => {
        //  console.log('111111111111111111111',response.data.allSlProjects.nodes)
          this.temp = response.data.allSlProjects.nodes[0]
        })
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const tempData = Object.assign({}, this.temp)
          let query = {
            "operationName": "updateSlProjectByPid",
            "query": "mutation updateSlProjectByPid($input: UpdateSlProjectByPidInput!) { updateSlProjectByPid(input: $input) { slProject { pid } } }",
            "variables": {input: {pid: this.pid, slProjectPatch:tempData}}
          }

          GQL(query).then((res) => {
            // const index = this.list.findIndex(v => v.id === this.temp.id)
               if(res.errors){
                  this.$notify({
                    title: '修改失败',
                    message: '修改项目失败',
                    type: 'error',
                    duration: 2000
                  })
              }else{
                  // this.list.splice(index, 1, this.temp)
                  this.dialogFormVisible = false
                  this.$notify({
                    title: '修改成功',
                    message: '修改项目成功',
                    type: 'success',
                    duration: 2000
                  })
                  
              }
       
          })
        }
      })
    },
  }
 
}
</script>

